# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:html2txt1_0.py
@Time:2024/9/4 21:47

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
import requests

# 网址
url = 'https://www.stats.gov.cn/sj/tjgb/ndtjgb/qgndtjgb/202302/t20230206_1901956.html'

# 使用requests库获取网址内容
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 打印响应的编码（注意：这可能只是响应头中声明的编码，实际内容可能不同）
    print("Response encoding:", response.encoding)

    # 尝试使用response.encoding编码来解码内容
    content = response.text

    # 将内容写入到TXT文件中
    with open('website_content.txt', 'w', encoding='ISO-8859-1') as file:
        file.write(content)
else:
    print('Failed to retrieve the webpage')

